<template>
  <div class="header-container">
    <div class="l-content">
      <el-button @click="handleMenu" icon="el-icon-menu" size="mini"></el-button>
      <span class="text">中医诊所在线预约系统</span>
    </div>
    <div common-header class="r-content">
      <el-dropdown @command="handleClick">
        <span class="el-dropdown-link">
          <img class="headPic" src="../assets/img/user.png">
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="loginOut">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import Cookie from 'js-cookie'
import Utils from '../api/utils'

export default {
  name: 'CommonHeader',
  methods: {
    handleMenu () {
      this.$store.commit('collapseMenu')
    },
    handleClick (command) {
      if (command === 'loginOut') {
        Utils.$emit('addRoutes', {type: ''})
        Cookie.remove('token')
        localStorage.clear()
        this.$router.replace({path: '/login'})
        location.reload()
      }
    }
  }
}
</script>

<style lang="less" scoped>
.header-container{
  padding: 0px 20px;
  background-color: #2785f8;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .text{
    color: #fff;
    font-size: 16px;
    margin-left: 10px;
  }
  .r-content{
    .headPic{
      width: 40px;
      height: 40px;
      border-radius: 50%;
    }
  }
}
</style>
